package com.gs.librarian.model.entity;



import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;


/**
 * @author  sabuj.das
 * @MailTo  sabuj.das@gmail.com
 */
@Entity
@Table(name = "eb_role")
public class Role implements java.io.Serializable {

	/**
	 * @uml.property  name="roleId"
	 */
	private long roleId;
	/**
	 * @uml.property  name="roleTitle"
	 */
	private String roleTitle;
	/**
	 * @uml.property  name="roleDescription"
	 */
	private String roleDescription;
	/**
	 * @uml.property  name="versionNo"
	 */
	private int versionNo;
	/**
	 * @uml.property  name="permissions"
	 */
	private Set<Permission> permissions = new HashSet<Permission>(0);
	/**
	 * @uml.property  name="users"
	 */
	private Set<User> users = new HashSet<User>(0);
	/**
	 * @uml.property  name="auditProperties"
	 * @uml.associationEnd  
	 */
	private AuditProperties auditProperties;

	public Role() {
	}

	/**
	 * @return
	 * @uml.property  name="roleId"
	 */
	@Id
	@GeneratedValue
	@Column(name = "ROLE_ID", unique = true, nullable = false)
	public long getRoleId() {
		return this.roleId;
	}

	/**
	 * @param roleId
	 * @uml.property  name="roleId"
	 */
	public void setRoleId(long roleId) {
		this.roleId = roleId;
	}

	/**
	 * @return
	 * @uml.property  name="roleTitle"
	 */
	@Column(name = "ROLE_TITLE", nullable = false, length = 50)
	public String getRoleTitle() {
		return this.roleTitle;
	}

	/**
	 * @param roleTitle
	 * @uml.property  name="roleTitle"
	 */
	public void setRoleTitle(String roleTitle) {
		this.roleTitle = roleTitle;
	}

	/**
	 * @return
	 * @uml.property  name="roleDescription"
	 */
	@Column(name = "ROLE_DESCRIPTION")
	public String getRoleDescription() {
		return this.roleDescription;
	}

	/**
	 * @param roleDescription
	 * @uml.property  name="roleDescription"
	 */
	public void setRoleDescription(String roleDescription) {
		this.roleDescription = roleDescription;
	}

	/**
	 * @return
	 * @uml.property  name="versionNo"
	 */
	@Version
	@Column(name = "VERSION_NO", nullable = false, columnDefinition=" integer default 0 " )
	public int getVersionNo() {
		return this.versionNo;
	}

	/**
	 * @param versionNo
	 * @uml.property  name="versionNo"
	 */
	public void setVersionNo(int versionNo) {
		this.versionNo = versionNo;
	}

	/**
	 * @return
	 * @uml.property  name="permissions"
	 */
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "role")
	public Set<Permission> getPermissions() {
		return this.permissions;
	}

	/**
	 * @param permissions
	 * @uml.property  name="permissions"
	 */
	public void setPermissions(Set<Permission> permissions) {
		this.permissions = permissions;
	}

	/**
	 * @return
	 * @uml.property  name="users"
	 */
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "user_role_map", 
		joinColumns = { @JoinColumn(name = "ROLE_ID") }, 
		inverseJoinColumns = { @JoinColumn(name = "USER_ID") })
	public Set<User> getUsers() {
		return users;
	}

	/**
	 * @param users
	 * @uml.property  name="users"
	 */
	public void setUsers(Set<User> users) {
		this.users = users;
	}

	/**
	 * @return
	 * @uml.property  name="auditProperties"
	 */
	@Embedded
	public AuditProperties getAuditProperties() {
		return auditProperties;
	}

	/**
	 * @param auditProperties
	 * @uml.property  name="auditProperties"
	 */
	public void setAuditProperties(AuditProperties auditProperties) {
		this.auditProperties = auditProperties;
	}

}
